/*
 * Copyright (c) 2022  by Junzhao
 * THIS FILE IS PART OF JAVASE Song Huongkang PROJECT
 * All Rights Reserved.
 */

package 泛型练习;

import org.junit.Test;

import java.util.List;

/**
 * @Description
 * @Author 俊昭
 * @Date 2022/4/22
 */
public class DAO_Test {
    @Test
    public void t(){
        User u1 = new User("Hu",1001,12);
        User u2 = new User("Guo",1002,18);
        User u3 = new User("Bai",1003,15);
        User u4 = new User("Yang",1004,22);
        User u5 = new User("Zhao",1005,20);

        User u6 = new User("Jin",1006,23);
        User u7 = new User("Liu",1007,34);

        DAO<User> userDAO = new DAO<>();
        // save
        userDAO.save("①",u1);
        userDAO.save("②",u2);
        userDAO.save("③",u3);
        userDAO.save("④",u4);
        userDAO.save("⑤",u5);


        // get
        User u8 = userDAO.get("④");
        System.out.println(u8);// User{name='Yang', id=1004, age=22}

        // update
        userDAO.update("⑤",u6);
        System.out.println(userDAO.get("⑤"));// User{name='Jin', id=1006, age=23}

        // list
        List<User> l = userDAO.list();
        System.out.println(l);
        // [User{name='Hu', id=1001, age=12},
        // User{name='Guo', id=1002, age=18},
        // User{name='Bai', id=1003, age=15},
        // User{name='Yang', id=1004, age=22},
        // User{name='Jin', id=1006, age=23}]

        // delete
        userDAO.delete("③");
        List<User> l1 = userDAO.list();
        System.out.println(l1);
        // [User{name='Hu', id=1001, age=12},
        // User{name='Guo', id=1002, age=18},
        // User{name='Yang', id=1004, age=22},
        // User{name='Jin', id=1006, age=23}]



    }
}
